﻿package plugin.sbkinfo
{
    import __AS3__.vec.*;
    import base.component.*;
    import cmd.*;
    import com.core.*;
    import com.sh.game.consts.*;
    import com.sh.game.display.*;
    import com.sh.game.net.*;
    import com.sh.game.util.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.component.*;
    import uiresource.sbkinfo.*;
    import vo.*;

    public class SbkCrl extends SbkUI
    {
        private var mUiBase:SbkInfo;
        private var _roleContainerVec:Vector.<Container>;
        private var _role1:SimpleRoleManager;
        private var _role2:SimpleRoleManager;
        private var _role3:SimpleRoleManager;
        private var _role4:SimpleRoleManager;
        private var _role5:SimpleRoleManager;
        private var _role6:SimpleRoleManager;
        private const posX:int = 525;
        private const posY:int = 407;
        private var pointarr:Array;
        private var _timeID:uint = 0;
        private var _letime:int = 0;
        private var _sbkinfo:Object;
        private var _cfgitems:Object;
        private var mc:XMLMovieClip;

        public function SbkCrl(param1:SbkInfo)
        {
            this.pointarr = [[this.posX, this.posY], [this.posX + 178, this.posY], [this.posX - 131, this.posY + 103], [this.posX + 330, this.posY + 103], [this.posX - 296, this.posY + 164], [this.posX + 486, this.posY + 164]];
            this._sbkinfo = ConfigDictionary.data.sbkinfo;
            this._cfgitems = ConfigDictionary.data.item;
            this.mUiBase = param1;
            return;
        }// end function

        public function openRefresh() : void
        {
            Server.instance.sendBuffer(61, CMDSBK.SBKSend, null, 0, ConnectType.SYSTEM);
            return;
        }// end function

        override protected function createChildren() : void
        {
            viewClassMap["uiresource.sbkinfo.ZzgzUI"] = ZzgzUI;
            loadUI("Sbk.xml");
            return;
        }// end function

        public function init(param1:Object) : void
        {
            var _loc_12:int = 0;
            var _loc_17:Object = null;
            var _loc_2:* = param1.StartTime;
            var _loc_3:* = new Date(_loc_2 * 1000);
            var _loc_4:* = param1.Unionname;
            var _loc_5:* = param1.Time;
            var _loc_6:* = param1.Chengzhu;
            var _loc_7:* = param1.Chengzhufuren;
            var _loc_8:* = param1.Fuchengzhu;
            var _loc_9:* = param1.Dazhanglao;
            var _loc_10:* = param1.Dajiangjun;
            var _loc_11:* = param1.Dayuanshuai;
            if (_loc_5)
            {
                uniontime.text = _loc_5 + "天";
            }
            else if (_loc_4)
            {
                uniontime.text = "不到一天";
            }
            else
            {
                uniontime.text = "无";
            }
            var _loc_13:Array = [_loc_6, _loc_7, _loc_8, _loc_9, _loc_10, _loc_11];
            if (_loc_4)
            {
                unionname.color = "0xe19f21";
                unionname.text = _loc_4;
                _loc_12 = 0;
                while (_loc_12 < 6)
                {
                    
                    _loc_17 = _loc_13[_loc_12];
                    if (_loc_17 != null)
                    {
                        this.refresh(_loc_12, _loc_17);
                        (this["name" + (_loc_12 + 1)] as Label).text = _loc_17.name;
                    }
                    else
                    {
                        (this["name" + (_loc_12 + 1)] as Label).text = "虚位以待";
                        this.refresh(_loc_12, null);
                    }
                    _loc_12++;
                }
            }
            else
            {
                unionname.text = "无";
                _loc_12 = 0;
                while (_loc_12 < 6)
                {
                    
                    (this["name" + (_loc_12 + 1)] as Label).text = "虚位以待";
                    _loc_12++;
                }
            }
            var _loc_14:* = new Date(_loc_3.fullYear, _loc_3.month, _loc_3.date, 20, 0, 0, 0);
            var _loc_15:* = ModelProxy.getValue("data", "servertime") + getTimer();
            var _loc_16:* = new Date(_loc_15);
            if (_loc_14.time <= _loc_16.time && _loc_3.time >= _loc_16.time)
            {
                kztime.text = "开战中";
                this._letime = (_loc_3.time - _loc_16.time) / 1000;
                this._timeID = setInterval(this.opentimeRun, 1000);
            }
            else
            {
                kztime.text = "开战时间:" + _loc_14.fullYear + "年" + (_loc_14.month + 1) + "月" + _loc_14.date + "日20:00";
                lestime.text = "";
            }
            return;
        }// end function

        private function opentimeRun() : void
        {
            if (this._letime == 0)
            {
                lestime.text = "";
                if (this._timeID > 0)
                {
                    clearInterval(this._timeID);
                    this._timeID = 0;
                }
                return;
            }
            var _loc_1:String = this;
            var _loc_2:* = this._letime - 1;
            _loc_1._letime = _loc_2;
            lestime.text = "剩余时间:" + TimeDataFormatUtil.getLeftTime(this._letime);
            return;
        }// end function

        public function refresh(param1:int, param2:Object) : void
        {
            var _loc_5:Object = null;
            var _loc_3:* = this["_role" + (param1 + 1)];
            var _loc_4:* = this._roleContainerVec[param1];
            if (param2 == null)
            {
                if (_loc_3)
                {
                    _loc_3.removeRole(true);
                }
            }
            else
            {
                _loc_5 = param2;
                _loc_5.arms = param2.arms;
                _loc_5.fashions = param2.fashion;
                if (_loc_3)
                {
                    _loc_3.updateRoel(_loc_5);
                }
                else
                {
                    _loc_3 = new SimpleRoleManager(_loc_5, _loc_4);
                }
            }
            return;
        }// end function

        override protected function initializeView() : void
        {
            var _loc_1:int = 0;
            var _loc_8:Container = null;
            super.initializeView();
            var _loc_2:* = new Sprite();
            _loc_2.graphics.beginFill(16772608, 0);
            _loc_2.graphics.drawRect(800, 230, 56, 207);
            _loc_2.graphics.endFill();
            var _loc_3:* = ItemObject.create(this._cfgitems[242202016]);
            var _loc_4:* = new ActorMovie(_loc_3);
            new ActorMovie(_loc_3).x = 690;
            _loc_4.y = 220;
            _loc_4.mouseChildren = false;
            _loc_4.mouseEnabled = false;
            guize.addChild(_loc_4);
            guize.addChild(_loc_2);
            _loc_2.addEventListener(MouseEvent.MOUSE_OVER, this.Ontips);
            var _loc_5:* = Control.create(SbkContrl, this);
            ModelProxy.addObserver("sbkinfo", _loc_5);
            this._roleContainerVec = new Vector.<Container>;
            _loc_1 = 0;
            while (_loc_1 < 6)
            {
                
                _loc_8 = new Container();
                rolebox.addChild(_loc_8);
                _loc_8.x = this.pointarr[_loc_1][0];
                _loc_8.y = this.pointarr[_loc_1][1];
                this._roleContainerVec.push(_loc_8);
                _loc_8.mouseChildren = false;
                _loc_8.mouseEnabled = false;
                _loc_1++;
            }
            var _loc_6:Array = [];
            _loc_1 = 1;
            while (_loc_1 <= 4)
            {
                
                _loc_6.push(this._sbkinfo[_loc_1]);
                _loc_1++;
            }
            guize.list.renderHandler = new Handler(this.listRenderHandler);
            guize.list.array = _loc_6;
            var _loc_7:Array = [];
            _loc_1 = 5;
            while (_loc_1 <= 8)
            {
                
                _loc_7.push(this._sbkinfo[_loc_1]);
                _loc_1++;
            }
            guize.list1.renderHandler = new Handler(this.listRenderHandler1);
            guize.list1.array = _loc_7;
            guize.visible = false;
            this.initEvent();
            return;
        }// end function

        protected function Ontips(event:MouseEvent) : void
        {
            var _loc_2:* = this._cfgitems[242202016];
            ModelProxy.change("tips", "arm", {data:_loc_2, p:new Point(event.stageX, event.stageY)});
            event.currentTarget.addEventListener(MouseEvent.MOUSE_OUT, this.OnCloselvtips);
            return;
        }// end function

        protected function OnCloselvtips(event:MouseEvent) : void
        {
            event.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT, this.OnCloselvtips);
            ModelProxy.change("tips", "state", "close");
            return;
        }// end function

        private function listRenderHandler1(param1:Component, param2:int) : void
        {
            var temparr:Array;
            var talk:Array;
            var item:* = param1;
            var index:* = param2;
            if (index < guize.list1.length)
            {
                temparr;
                (item as GuizeItemUI).ntxt.text = item.dataSource.name;
                talk = String(item.dataSource.dec).split("@");
                (item as GuizeItemUI).nlist.renderHandler = new Handler(function (param1:Component, param2:int) : void
            {
                if (param2 < (item as GuizeItemUI).nlist.length)
                {
                    (param1.getChildByName("dectxt") as Label).text = (item as GuizeItemUI).nlist.array[param2];
                }
                return;
            }// end function
            );
                (item as GuizeItemUI).nlist.array = talk;
            }
            return;
        }// end function

        private function listRenderHandler(param1:Component, param2:int) : void
        {
            var temparr:Array;
            var talk:Array;
            var item:* = param1;
            var index:* = param2;
            if (index < guize.list.length)
            {
                temparr;
                (item as GuizeItemUI).ntxt.text = item.dataSource.name;
                talk = String(item.dataSource.dec).split("@");
                (item as GuizeItemUI).nlist.renderHandler = new Handler(function (param1:Component, param2:int) : void
            {
                if (param2 < (item as GuizeItemUI).nlist.length)
                {
                    (param1.getChildByName("dectxt") as Label).text = (item as GuizeItemUI).nlist.array[param2];
                }
                return;
            }// end function
            );
                (item as GuizeItemUI).nlist.array = talk;
            }
            return;
        }// end function

        private function onComp(param1:Object) : void
        {
            var _loc_2:* = new XML(new SBKEmbeds.mobaiXML());
            this.mc = new XMLMovieClip("mobai", _loc_2);
            this.mc.interval = 1000 / 15;
            this.mc.x = -140;
            this.mc.y = -127;
            this.mc.mouseChildren = false;
            this.mc.mouseEnabled = false;
            return;
        }// end function

        private function initEvent() : void
        {
            close.clickHandler = new Handler(this.clickHandler);
            glbtn.clickHandler = new Handler(this.glbtnHandler);
            gsbtn.clickHandler = new Handler(this.gsHandler);
            guize.btn_close.clickHandler = new Handler(this.closegzHandler);
            return;
        }// end function

        private function closegzHandler() : void
        {
            guize.visible = false;
            return;
        }// end function

        private function gsHandler() : void
        {
            var _loc_1:String = "119#151#176#1116";
            var _loc_2:* = _loc_1.split("#");
            PluginManager.instance.sendToServer("activity", CMDActivity.Trans, {x:_loc_2[1], y:_loc_2[2], tostageid:_loc_2[3], free:1});
            this.onclose();
            return;
        }// end function

        private function glbtnHandler() : void
        {
            guize.visible = true;
            return;
        }// end function

        private function clickHandler() : void
        {
            this.onclose();
            return;
        }// end function

        public function onclose() : void
        {
            this.mUiBase.close();
            return;
        }// end function

    }
}
